home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / MMID.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  1KB  |  37 lines

  1. PROCEDURE mmid(y,dydx: glnarray; nvar: integer; xs,htot: real;
  2.       nstep: integer; VAR yout: glnarray);
  3. (* Programs using routine MMID must provide a
  4. PROCEDURE derivs(x:real; y:glnarray; VAR dydx:glnarray);
  5. which returns the derivatives dydx at location x, given both x and the
  6. function values y. They must also define the type
  7. TYPE
  8.    glnarray = ARRAY [1..nvar] OF real;
  9. in the main routine.  Note that this routine is in
  10. single precision, unlike the FORTRAN version. *)
  11. VAR
  12.    n,i: integer;
  13.    x,swap,h2,h: real;
  14.    ym,yn: glnarray;
  15. BEGIN
  16.    h := htot/nstep;
  17.    FOR i := 1 TO nvar DO BEGIN
  18.       ym[i] := y[i];
  19.       yn[i] := y[i]+h*dydx[i]
  20.    END;
  21.    x := xs+h;
  22.    derivs(x,yn,yout);
  23.    h2 := 2.0*h;
  24.    FOR n := 2 TO nstep DO BEGIN
  25.       FOR i := 1 TO nvar DO BEGIN
  26.          swap := ym[i]+h2*yout[i];
  27.          ym[i] := yn[i];
  28.          yn[i] := swap
  29.       END;
  30.       x := x+h;
  31.       derivs(x,yn,yout)
  32.    END;
  33.    FOR i := 1 TO nvar DO BEGIN
  34.       yout[i] := 0.5*(ym[i]+yn[i]+h*yout[i])
  35.    END
  36. END;
  37.